package com.ruoyi.asktreat.controller;

import java.util.List;
import java.util.Random;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asktreat.domain.AskTreat;
import com.ruoyi.asktreat.service.IAskTreatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 治疗管理Controller
 * 
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/ask/treat")
public class AskTreatController extends BaseController
{
    @Autowired
    private IAskTreatService askTreatService;

    /**
     * 查询治疗管理列表
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:list')")
    @GetMapping("/list")
    public TableDataInfo list(AskTreat askTreat)
    {
        startPage();
        List<AskTreat> list = askTreatService.selectAskTreatList(askTreat);
        return getDataTable(list);
    }

    /**
     * 导出治疗管理列表
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:export')")
    @Log(title = "治疗管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AskTreat askTreat)
    {
        List<AskTreat> list = askTreatService.selectAskTreatList(askTreat);
        ExcelUtil<AskTreat> util = new ExcelUtil<AskTreat>(AskTreat.class);
        util.exportExcel(response, list, "治疗管理数据");
    }

    /**
     * 获取治疗管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:query')")
    @GetMapping(value = "/{treatId}")
    public AjaxResult getInfo(@PathVariable("treatId") Long treatId)
    {
        return success(askTreatService.selectAskTreatByTreatId(treatId));
    }

    /**
     * 新增治疗管理
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:add')")
    @Log(title = "治疗管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AskTreat askTreat)
    {
        Random random = new Random();
        // 生成100000到999999之间的随机数，确保是6位数
        int randomNumber = 10000000 + random.nextInt(90000000);
        String code6 = ""+randomNumber;
        String uuid = UUID.randomUUID().toString();
        askTreat.setTreatCode8(code6);
        //askTreat.settrea(uuid);
        return toAjax(askTreatService.insertAskTreat(askTreat));
    }

    /**
     * 修改治疗管理
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:edit')")
    @Log(title = "治疗管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AskTreat askTreat)
    {
        return toAjax(askTreatService.updateAskTreat(askTreat));
    }

    /**
     * 删除治疗管理
     */
    @PreAuthorize("@ss.hasPermi('ask:treat:remove')")
    @Log(title = "治疗管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{treatIds}")
    public AjaxResult remove(@PathVariable Long[] treatIds)
    {
        return toAjax(askTreatService.deleteAskTreatByTreatIds(treatIds));
    }
}
